package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.domain.SetmealDish;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//套餐分类
@RestController
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    //分页+模糊查询
    @GetMapping("/setmeal/page")
    public ResultInfo  findByPage(@RequestParam(name = "page",defaultValue = "1") Integer pageNum,
                                  @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize,
                                  String name){
        //调用service查询
        Page<Setmeal> page = setmealService.findByPage(pageNum,pageSize,name);

        //返回数据
        return ResultInfo.success(page);
    }

    // 新增套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal) { // 1.接收参数
        // 2.调用service新增
        setmealService.save(setmeal);
        // 3.返回结果
        return ResultInfo.success();
    }

    // 删除套餐
    @DeleteMapping("/setmeal")
    public ResultInfo deleteBatch(@RequestParam List<Long> ids) { // 1.接收参数
        // 2.调用service删除
        setmealService.deleteBatch(ids);
        // 3.返回结果
        return ResultInfo.success();
    }

    //根据Id回显信息
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable("id") Long id){
        Setmeal setmeal=setmealService.findById(id);
        return ResultInfo.success(setmeal);
    }

    //修改套餐
    @PutMapping("/setmeal")
    public ResultInfo update(@RequestBody Setmeal setmeal){
        setmealService.update(setmeal);
        return ResultInfo.success();
    }


    //停售/启售
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo status(
            @PathVariable("status") Integer status,
            @RequestParam("ids") List<Long> ids
    ){
        setmealService.status(status, ids);
        return ResultInfo.success();
    }




}
